#include "header.h"

int main() {
	setbuf(stdout,NULL);//For eclipse printf error
    //int sign_num = 0;
    int runFlag = 1;
    printf("Main begin\n");
    show_menu();
    while (runFlag) {
        //show_menu();
        select_problem(&runFlag);
        //printf("Press any key to continue...");
        //getchar();
    }
    printf("Main End\n");
    return 0;
}

int show_menu() {
    FILE *fpt = NULL;
    char listLoader;
    fpt = fopen("Resource/pgm_list.txt", "r");
    /*Load file begin here*/
    if (fpt == NULL)//check the file load is false
    {
        printf("List load fail , program gonna exit...\n");
        system("pause");
        exit(true);
    }
    /*-Show menu begin here-*/
    printf("ACM Problem Main menu \n");

    for ( listLoader = getc(fpt); ( (listLoader != EOF) && !feof(fpt) );listLoader = getc(fpt) ) {
        printf("%c", listLoader);
    }
    printf("\n");
    /*-Show menu end here-*/
    fclose(fpt);
    /*Load file end here-*/
    return 0;
}

int select_problem(int *runFlag) {
    int ProblemSelect;
    printf("Enter the problem's number to execute : ");
    scanf(" %d", &ProblemSelect);
    fflush(stdin);
    switch (ProblemSelect) {
        case 100:
            acm_00100();
            break;
        case 272:
            acm_00272();
            break;
        case 458:
            acm_00458();
            break;
        case 476:
            acm_00476();
            break;
        case 477:
            acm_00477();
            break;
        case 488:
            acm_00488();
            break;
        case 494:
            acm_00494();
            break;
        case 579:
            acm_00579();
            break;
        case 591:
            acm_00591();
            break;
        case 10019:
            acm_10019();
            break;
        case 10055:
            acm_10055();
            break;
        case 10071:
            acm_10071();
            break;
        case 10370:
            acm_10370();
            break;
        case 913:
            acm_00913();
            break;
        case 10018:
            acm_10018();
            break;
        case 10924:
            acm_10924();
            break;
        case 11172:
            acm_11172();
            break;
        case 0:
            printf("Are you sure to quit this program ?\n");
            printf("Enter 0 to quit , or enter 1 to continue : ");
            scanf(" %d", runFlag);
            fflush(stdin);
            break;
        case -1:
            test();
            break;
        default:
            printf("Wrong choice , please choose again\n");
            break;
    }
    return 0;
}
